<?php

//Load QCubed Framework...
require_once('../../../qcubed.inc.php');

//Load Storage Interface
require_once( 'storage.interface.php');

//Load External Libraries
require_once(__INCLUDES__ . '/external_libraries/cloudinary/Cloudinary.php');
require_once(__INCLUDES__ . '/external_libraries/cloudinary/Uploader.php');
require_once(__INCLUDES__ . '/external_libraries/cloudinary/Api.php');

class CloudinaryStorage implements StorageInterface {

    protected $objSetting;

    public function __construct() {
        $this->objSetting = Setting::LoadKeyValueArrayByKeys('cloudinary_cloudname', 'cloudinary_api_key', 'cloudinary_secret');
    }

    public function Init() {

        \Cloudinary::config(array(
            cloud_name => $this->objSetting['cloudinary_cloudname'],
            api_key => $this->objSetting['cloudinary_api_key'],
            api_secret => $this->objSetting['cloudinary_secret']
        ));
    }

    public function Upload($strPath, $objOptionsArray) {
        $this->Init();
        return \Cloudinary\Uploader::upload($strPath, $objOptionsArray);
    }

    public function Delete($strInternal) {
        $this->Init();
        return \Cloudinary\Uploader::destroy($strInternal);
    }

    public function Get($strInternal, $strOptions) {
        return \Cloudinary::cloudinary_url($strInternal, $strOptions);
    }

}

?>